//
//  CollecCellForScroll.m
//  PCAForWar
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CollecCellForScroll.h"
#import "ModelForPicScroll.h"
#import "Model.h"
#import <UIImageView+WebCache.h>


@interface CollecCellForScroll ()

@property (nonatomic, retain) UIImageView *imageView;
//@property (nonatomic, assign) BOOL isBig1;
//@property (nonatomic, assign) BOOL isBig2;

@end

@implementation CollecCellForScroll

- (void)dealloc{
    
    [_imageView release];
    [super dealloc];
}


- (instancetype) initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createImageView];
    }
    
    return self;
}

- (void)createImageView {
    
    self.imageView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:self.imageView];
    
    self.imageView.backgroundColor = [UIColor blackColor];
    
    self.imageView.userInteractionEnabled = YES;
    
    [_imageView release];
    
//    [self tap];
    
}

#pragma mark 图片自适应高度
+ (CGFloat)heightForImage:(UIImage *)image {
    
    return image.size.height / image.size.width * ([UIScreen mainScreen].bounds.size.width - 20);
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    if (self.imageView.image.size.height) {
        
        self.imageView.frame = CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width - 20, [[self class]heightForImage:self.imageView.image]);
        
        self.imageView.center = self.contentView.center;
    }

}

- (void)passModelPicScroll:(UIImage *)img {
    
    self.imageView.image = img;
    
}





#pragma mark 实现图片放大缩小
//- (void)tap {
//    
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//    
//    tap.numberOfTapsRequired = 2;
//    
//    [self.imageView addGestureRecognizer:tap];
//    
//    [tap release];
//}
//
//- (void)tapAction:(UITapGestureRecognizer *)tap {
//    
//    if (self.isBig1) {
//        
//        [UIView animateWithDuration:0.25 animations:^{
//            
//            tap.view.transform = CGAffineTransformScale(tap.view.transform, 1.5, 1.5);
//        }];
//        
//        // 取反
//        self.isBig1 = !self.isBig1;
//        self.isBig2 = self.isBig2;
//    
//    } else if (self.isBig2) {
//        
//        [UIView animateWithDuration:0.25 animations:^{
//            
//            tap.view.transform = CGAffineTransformScale(tap.view.transform, 1.5, 1.5);
//        }];
//        
//        // 取反.
//        self.isBig1 = self.isBig1;
//        self.isBig2 = !self.isBig2;
//        
//        
//    } else {
//        
//        [UIView animateWithDuration:0.25 animations:^{
//            
//            self.imageView.frame = CGRectMake(0, self.frame.size.height / 2 - self.frame.size.width / 800 * 500 / 2, self.frame.size.width, self.frame.size.width / 800 * 500);
//            
//        }];
//        
//        self.isBig1 = !self.isBig1;
//        self.isBig2 = !self.isBig2;
//    }
//  
//}


@end
